home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / ICON_UTL / TPICONS / ICONMAN.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-20  |  9KB  |  227 lines

  1. {---------------------------------------------------------------------------}
  2. { UNIT     : ICONMAN.PAS - Version 1.0                                      }
  3. {                                                                           }
  4. { FUNCTION : Provides Icon Management Routines.                             }
  5. {                                                                           }
  6. { AUTHOR   : Andy Denton - 06/08/91                                         }
  7. {                                                                           }
  8. {---------------------------------------------------------------------------}
  9.  
  10. UNIT ICONMAN;
  11.  
  12. INTERFACE
  13.  
  14. USES Graph;
  15.  
  16. {--------------------------------------------------------------------}
  17. { The following Procedures, Constants and Variables are visible to   }
  18. { the calling Programs.                                              }
  19. {--------------------------------------------------------------------}
  20. TYPE
  21.   BorderType = (Border,NoBorder);
  22.  
  23. VAR
  24.   FLoadResult   : INTEGER;
  25.   ICreateResult : INTEGER;
  26.  
  27. PROCEDURE OpenIconSystem;
  28. PROCEDURE CloseIconSystem;
  29. PROCEDURE LoadIconFile(Filename : STRING);
  30. PROCEDURE SaveIconFile(Filename : STRING);
  31. PROCEDURE DisplayIcon(Ino : INTEGER; Ix,Iy : INTEGER; BordTyp : BorderType; Color: WORD);
  32. PROCEDURE GetNumberOfIcons(VAR NoIco : INTEGER);
  33. PROCEDURE CreateIcon(Ino : INTEGER; Ix,Iy : INTEGER);
  34. PROCEDURE ReplaceIcon(Ino : INTEGER; Ix,Iy : INTEGER);
  35. PROCEDURE SetIconCount(MaxIco : INTEGER);
  36.  
  37. {--------------------------------------------------------------------}
  38. { The following Procedures, Constants and Variables are Private and  }
  39. { are not visible to the calling Programs.                           }
  40. {--------------------------------------------------------------------}
  41.  
  42. IMPLEMENTATION
  43.  
  44. CONST
  45.   Icon_Size : WORD    = 518;  { Number of bytes per 32x32 bit icon. }
  46.   Max_Icons : INTEGER = 32;   { Maximum number of icons per file.   }
  47.  
  48. TYPE
  49.   Icon_Record = RECORD        { Makes up Icon_Stack array. }
  50.   Icon_Pointer : POINTER;
  51.   END;
  52.  
  53. VAR
  54.   Loop         : INTEGER;
  55.   Number_Icons : BYTE;        { Number of icons in current file. }
  56.   F1           : FILE;
  57.   Current_File : STRING;      { Name of current file. }
  58.   result       : WORD;
  59.   HeapTop      : ^WORD;       { Marks bottom of reserved }
  60.                               { space for Icon_Stack.    }
  61.  
  62.   Icon_Stack   : ARRAY[1..32] OF Icon_Record; { Holds 32 icons }
  63.  
  64. {--------------------------------------------------------------------}
  65. { (1) OpenIconSystem                                                 }
  66. {                                                                    }
  67. { Reserve memory for all 32 icons on the heap.                       }
  68. {--------------------------------------------------------------------}
  69.  
  70. PROCEDURE OpenIconSystem;
  71. BEGIN
  72.   FOR loop:=1 TO Max_Icons DO
  73.   BEGIN
  74.     GetMem(Icon_Stack[Loop].Icon_Pointer, Icon_Size);  { Reserve memory for }
  75.   END;                                                 { all 32 icons       }
  76. END;
  77.  
  78. {--------------------------------------------------------------------}
  79. { (2) CloseIconSystem                                                }
  80. {                                                                    }
  81. { Discards heap memory used to hold all 32 icons.                    }
  82. {--------------------------------------------------------------------}
  83.  
  84. PROCEDURE CloseIconSystem;
  85. BEGIN
  86.  FOR loop:=1 TO Max_Icons DO
  87.   BEGIN
  88.     FreeMem(Icon_Stack[Loop].Icon_Pointer,Icon_Size);  { Restore memory taken }
  89.   END;                                                 { by all 32 icons      }
  90. END;
  91.  
  92. {--------------------------------------------------------------------}
  93. { (3) PROCEDURE LoadIconFile                                         }
  94. {                                                                    }
  95. { Loads an icon datafile (.IDF) into the Icon_Stack array.           }
  96. {--------------------------------------------------------------------}
  97.  
  98. PROCEDURE LoadIconFile(FileName : STRING);
  99. BEGIN
  100.   Assign(f1,FileName);
  101.   Reset(f1,1);                   { Reposition file pointer & record len = 1 }
  102.   FloadResult:=IOResult;
  103.   IF FLoadResult=0 THEN
  104.   BEGIN
  105.     Current_File:=FileName;
  106.     BlockRead(f1,Number_Icons,1,result);     { Read number of icons in file }
  107.     FOR Loop:=1 TO Max_Icons DO
  108.     BEGIN
  109.       BlockRead(f1,Icon_Stack[Loop].Icon_Pointer^,Icon_Size,result);    { Read Icon }
  110.     END;
  111.   Close(f1);
  112.   END
  113.   ELSE
  114.     Number_Icons:=0;
  115. END;
  116.  
  117. {--------------------------------------------------------------------}
  118. { (4) PROCEDURE SaveIconFile                                         }
  119. {                                                                    }
  120. { Saves the Icon_Stack array to an icon datafile (.IDF) on disk.     }
  121. {--------------------------------------------------------------------}
  122.  
  123. PROCEDURE SaveIconFile(FileName : STRING);
  124. BEGIN
  125.   IF FileName <>'' THEN
  126.   BEGIN
  127.     Assign(f1,FileName);
  128.     Rewrite(f1,1);                                  { Clear file & set record size to 1 }
  129.     BlockWrite(f1,Number_Icons,1,result);           { Write Icon number }
  130.     FOR loop:=1 TO Max_Icons Do
  131.     BEGIN
  132.       BlockWrite(f1,Icon_Stack[Loop].Icon_Pointer^,Icon_Size,result);  { Save Icon }
  133.     END;
  134.     Close(f1);
  135.   END;
  136. END;
  137.  
  138. {--------------------------------------------------------------------}
  139. { (5) DisplayIcon                                                    }
  140. {                                                                    }
  141. { Display an icon at a given X,Y screen coordinate.                  }
  142. {--------------------------------------------------------------------}
  143.  
  144. PROCEDURE DisplayIcon(Ino : INTEGER; Ix,Iy : INTEGER; BordTyp : BorderType; Color: WORD);
  145. VAR
  146.   OldColor : WORD;
  147. BEGIN
  148.   IF (Ino<=Number_Icons) AND (Ino>=1) THEN
  149.   PutImage(Ix,Iy,Icon_Stack[Ino].Icon_Pointer^, CopyPut);
  150.  
  151.   IF BordTyp=Border THEN
  152.   BEGIN
  153.     OldColor:=GetColor;
  154.     SetColor(Color);
  155.     Rectangle(Ix-1,Iy-1,Ix+32,Iy+32);
  156.     SetColor(OldColor);
  157.   END;
  158. END;
  159.  
  160. {--------------------------------------------------------------------}
  161. { (6) GetNumberOfIcons                                               }
  162. {                                                                    }
  163. { Returns the number of currently defined icons.                     }
  164. {--------------------------------------------------------------------}
  165.  
  166. PROCEDURE GetNumberOfIcons(VAR NoIco : INTEGER);
  167. BEGIN
  168.   NoIco:=Number_Icons;
  169. END;
  170.  
  171. {--------------------------------------------------------------------}
  172. { (7) CreateIcon                                                     }
  173. {                                                                    }
  174. { This allows the user to grab part of one of their screens in any   }
  175. { of their existing Turbo Pascal programs and use it as an icon.     }
  176. {--------------------------------------------------------------------}
  177.  
  178. PROCEDURE CreateIcon(Ino : INTEGER; Ix,Iy : INTEGER);
  179. BEGIN
  180.   ICreateResult:=0; { Ok }
  181.   IF (Ino<=(Number_Icons+1)) AND (Ino<=Max_Icons) AND (Ix+31<=639)
  182.   AND (Iy+31<=479) THEN
  183.   BEGIN
  184.     Getimage(Ix,Iy,Ix+31,Iy+31,Icon_Stack[Ino].Icon_Pointer^);
  185.     IF (Number_Icons<Max_Icons) THEN INC(Number_Icons);
  186.   END
  187.   ELSE
  188.   BEGIN
  189.     IF (Ino>=(Number_Icons+1)) OR (Ino>Max_Icons) THEN ICreateResult:=1;  { Invalid Icon }
  190.     IF (Ix+31>639) OR (Iy+31>479) THEN ICreateResult:=2;     { Part of the icon would be }
  191.   END;                                                       { grabbed from off screen   }
  192. END;
  193.  
  194. {--------------------------------------------------------------------}
  195. { (8) ReplaceIcon                                                    }
  196. {                                                                    }
  197. { This allows the user to grab part of one of their screens in any   }
  198. { of their existing Turbo Pascal programs and use it to replace an   }
  199. { existing icon.                                                     }
  200. {--------------------------------------------------------------------}
  201.  
  202. PROCEDURE ReplaceIcon(Ino : INTEGER; Ix,Iy : INTEGER);
  203. BEGIN
  204.   IF (Ino<=(Number_Icons)) AND (Ix+31<=639)
  205.   AND (Iy+31<=479) THEN
  206.   BEGIN
  207.     Getimage(Ix,Iy,Ix+31,Iy+31,Icon_Stack[Ino].Icon_Pointer^);
  208.   END
  209. END;
  210.  
  211. {--------------------------------------------------------------------}
  212. { (9) SetIconCount                                                   }
  213. {                                                                    }
  214. { Used to register a new icon. When an icon datafile is saved, the   }
  215. { variable Number_Icons is saved at the begining of the file.        }
  216. {--------------------------------------------------------------------}
  217.  
  218. PROCEDURE SetIconCount(MaxIco : INTEGER);
  219. BEGIN
  220.    IF (MaxIco>=0) AND (MaxIco<=32) THEN
  221.    BEGIN
  222.      Number_Icons:=MaxIco;
  223.    END;
  224. END;
  225.  
  226. END.
  227.